<template>
   <div>
      <!-- 搜索 -->
    <TopFilter
      :list="topFilterInit"
      :cols="3"
      labelWidth="100"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :isSelectColumn="isSelectColumn"
      :fetchapi="fetchParams"
      :params="flterValue"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="drawerHandle(null,'add')" >新增</el-button>
      </template>
    </FilterTable>
    <!-- 选择车型 -->
    <BaseDialog
      title="选择车型"
      :visible.sync="visibleDialog"
      width="700px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <typeCar   @close="closeTypeCarDialog" />
    </BaseDialog>

     <Drawer
      :visible.sync="visibleDrawer"
      title="活动方案新增"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-modal v-model="initData" @close="drawerClose" />
    </Drawer>
   </div>
</template>

<script>
import typeCar from '../commonForm/infoActivityTypeCar'
import infoModal  from './info'
import { dictionary } from '@/utils/dictMixin';
export default {
  mixins: [dictionary],
  components: {
    infoModal,typeCar
  },
  data() {
    return {
      visibleDialog:false,
      visibleDrawer:false,
      isSelectColumn: false,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      initData:{},
      columns: this.creatHeader(),
      fetchParams: null //ipa 接口
    }
  },
   mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  //方法、事件
  methods: {
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT',  label: '方案编号', fieldName: 'field0',  placeholder: '请选择', initialValue: ''},
        { type: 'INPUT',  label: '方案名称', fieldName: 'field1',  placeholder: '请选择', initialValue: ''},
        { type: 'SELECT', label: '方案状态', fieldName: 'field2', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1008') },
        { type: 'RANGE_DATE',  label: '方案下发日期',  fieldName: 'field22',  valueFormat: 'yyyy-MM-dd',   initialValue: '', placeholder: '请选择' },
        { type: 'INPUT',  label: '车型', fieldName: 'car',  placeholder: '请选择', initialValue: '', 
             unitRender: () => {
                    return <el-button slot="append" icon="el-icon-search" onClick={() =>this.openDialog()}></el-button>
              },
         },
        { type: 'INPUT', label: '活动名称', fieldName: 'field3', placeholder: '请选择', initialValue: '' },
        { type: 'SELECT', label: '是否全网下发', fieldName: 'field31', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1008') }
     ];
    },//搜索获取数据
    changeHandle(val) {
      this.flterValue = val;
      console.log(val);
    },
     //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.drawerHandle(props.row,'eidt')}>
                  编辑
                </el-button>
                <el-divider direction="vertical" />
                <el-button size="mini" type="text" onClick={() => this.drawerHandle(props.row,'show')}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        { title: '方案状态', dataIndex: 'field2', sorter: true ,
           render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
          }},
        { title: '方案编号', dataIndex: 'field3', sorter: true },
        { title: '方案名称', dataIndex: 'field4', sorter: true },
        { title: '活动周期', dataIndex: 'field6', sorter: true },
        { title: '创建人', dataIndex: 'field7', sorter: true },
        { title: '创建时间', dataIndex: 'field8', dateFormat:'yyyy-MM-dd',  sorter: true  },
        { title: '下发人', dataIndex: 'field80',  sorter: true  },
        { title: '下发时间', dataIndex: 'field9', dateFormat:'yyyy-MM-dd', sorter: true }
      ];
    },
    openDialog() {
      this.visibleDialog = true;
    },
    closeTypeCarDialog(data) {
      this.visibleDialog =false; //关闭弹窗
       //返回数据逻辑自己写
    },
    //详情
    drawerHandle(row,type) {
      //逻辑自己写
      this.initData =  {
        type: type,   //add/edit/show
        id:1001
      }; //行id
      this.visibleDrawer = true;
    },
    //关闭详情
    drawerClose() {
      this.visibleDrawer = false;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
     collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    }
  },
}
</script>

<style scoped>

</style>
